package com.app.enums;

/**
 * 角色枚举
 *
 * @Author 指缝de阳光
 * @Date 2022/7/20 15:04
 * @Version 1.0
 */
public enum FeedbackPeriodEnum {

    WEEK("周", 1),
    MONTH("月", 2),
    SEASON("季", 3),
    YEAR("年", 4);

    private final String name;
    private final Integer value;

    FeedbackPeriodEnum(String role, Integer value) {
        this.name = role;
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public Integer getValue() {
        return value;
    }


    public static FeedbackPeriodEnum valueOf2(Integer value) {
        FeedbackPeriodEnum periodEnum = null;
        try {
            periodEnum = getEnumByValue(FeedbackPeriodEnum.class, value);
            System.out.println("找到的枚举: " + periodEnum);
        } catch (IllegalArgumentException e) {
            System.out.println(e.getMessage());
        }
        return periodEnum;
    }

    // 假设 FeedbackPeriodEnum 是上面定义的枚举类型
    public static <E extends Enum<E>> E getEnumByValue(Class<E> enumClass, int value) {
        for (E enumConstant : enumClass.getEnumConstants()) {
            if (((FeedbackPeriodEnum) enumConstant).getValue() == value) {
                return enumConstant;
            }
        }
        throw new IllegalArgumentException("没有找到 value 为 " + value + " 的枚举实例");
    }
}
